﻿using System;

namespace PhotoFamily
{
	class Photo
	{
		string _title;
		public Photo(string title)
		{
			this._title = title;
		}
		public string Title
		{
			get
			{
				return _title;
			}
		}
	}
	class Album
	{
		// 该数组用于存放照片
		Photo[] photos;
		public Album(int capacity)
		{
			photos = new Photo[capacity];
		}
		public Photo this[int index]
		{
			get
			{
				// 验证索引范围
				if (index < 0 || index >= photos.Length)
				{
					Console.WriteLine("索引无效");
					// 使用 null 指示失败
					return null;
				}
				// 对于有效索引，返回请求的照片
				return photos[index];
			}
			set
			{
				if (index < 0 || index >= photos.Length)
				{
					Console.WriteLine("索引无效");
					return;
				}
				photos[index] = value;
			}
		}
		public Photo this[string title]
		{
			get
			{
				// 遍历数组中的所有照片
				foreach (Photo p in photos)
				{
					// 将照片中的标题与索引器参数进行比较
					if (p.Title == title)
						return p;
				}
				Console.WriteLine("未找到");
				// 使用 null 指示失败
				return null;
			}
		}
		static void Main(string[] args)
		{
			// 创建一个容量为 3 的相册
			Album family = new Album(5);
			family[0] = new Photo("Jeny ");
			family[1] = new Photo("Smith ");
			family[2] = new Photo("Lono ");
			family[3] = new Photo("Jack ");
			family[4] = new Photo("Lion ");
			foreach (Photo item in family.photos)
			{
				Console.WriteLine(item.Title);
			}
		
		}
	}
}
